package com.tanhua.server.controller;

import com.tanhua.server.pojo.User;
import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.vo.NearUserVo;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: JinboYang
 * @Description:
 * @Date: Created in 19:10 2021/1/4
 * @ModifiedBy:
 */
@RestController
@RequestMapping("tanhua")
@Slf4j
public class TodayBestController {
    @Autowired
    private TodayBestService todayBestService;

    /**
     * @Description: 查找今日佳人
     * @Param:[token]
     * @return:org.springframework.http.ResponseEntity<com.tanhua.server.vo.TodayBest>
     * @Author:JinboYang
     * @Date:2021/1/4
     */
    @GetMapping("todayBest")
    public ResponseEntity<TodayBest> queryTodayBest(@RequestHeader("Authorization") String token) {
        try {
            //调用业务层方法进行查询
            TodayBest todayBest = this.todayBestService.queryTodayBest(token);
            if (null != todayBest) {
                return ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
            log.error("查找今日佳人出错~ ", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * @Description: 查找推荐用户
     * @Param:[token, recommendUserQueryParam]
     * @return:org.springframework.http.ResponseEntity<com.tanhua.server.vo.PageResult>
     * @Author:JinboYang
     * @Date:2021/1/5
     */
    @GetMapping("recommendation")
    public ResponseEntity<PageResult> queryRecommendation(@RequestHeader("Authorization") String token,
                                                          RecommendUserQueryParam param) {
        try {
            PageResult pageResult = this.todayBestService.queryRecommendation(token, param);
            if (null != pageResult) {
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询推荐用户列表出错~", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }


    /**
     * @Description: 查看今日佳人详情
     * @Param:[userId]
     * @return:org.springframework.http.ResponseEntity<com.tanhua.server.vo.TodayBest>
     * @Author:JinboYang
     * @Date:2021/1/13
     */
    @GetMapping("{id}/personalInfo")
    public ResponseEntity<TodayBest> queryTodayBest(@PathVariable("id") Long userId) {
        try {
            TodayBest todayBest = this.todayBestService.queryTodayBest(userId);
            return ResponseEntity.ok(todayBest);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * @Description: 查询陌生人问题
     * @Param:[userId]
     * @return:org.springframework.http.ResponseEntity<java.lang.String>
     * @Author:JinboYang
     * @Date:2021/1/13
     */
    @GetMapping("strangerQuestions")
    public ResponseEntity<String> queryQuestion(@RequestParam("userId") Long userId) {
        try {
            String question = this.todayBestService.queryQuestion(userId);
            return ResponseEntity.ok(question);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * @Description: 回复陌生人问题
     * @Param:[param]
     * @return:org.springframework.http.ResponseEntity<java.lang.Void>
     * @Author:JinboYang
     * @Date:2021/1/13
     */
    @PostMapping("strangerQuestions")
    public ResponseEntity<Void> replyQuestion(@RequestBody Map<String, Object> param) {
        Long userId = Long.valueOf(param.get("userId").toString());
        String reply = param.get("reply").toString();
        Boolean result = this.todayBestService.replyQuestion(userId, reply);
        if (result) {
            return ResponseEntity.ok(null);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * @Description: 搜附近
     * @Param:[gender, distance]
     * @return:org.springframework.http.ResponseEntity<java.util.List<com.tanhua.server.vo.NearUserVo>>
     * @Author:JinboYang
     * @Date:2021/1/14
     */
    @GetMapping("search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(@RequestParam(value = "sex", required = false) String gender,
                                                          @RequestParam(value = "distance", defaultValue = "2000") String distance) {
        try {
            List<NearUserVo> list = this.todayBestService.queryNearUser(gender, distance);
            return ResponseEntity.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
       * @Description: 卡片列表
       * @Param:[]
       * @return:org.springframework.http.ResponseEntity<java.util.List<com.tanhua.server.vo.TodayBest>>
       * @Author:JinboYang
       * @Date:2021/1/14
       */
    @GetMapping("cards")
    public ResponseEntity<List<TodayBest>> queryCardsList() {
        try {
            List<TodayBest> list = this.todayBestService.queryCardsList();
            return ResponseEntity.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
       * @Description: 喜欢
       * @Param:[likeUserId]
       * @return:org.springframework.http.ResponseEntity<java.lang.Void>
       * @Author:JinboYang
       * @Date:2021/1/14
       */
    @GetMapping("{id}/love")
    public ResponseEntity<Void> likeUser(@PathVariable("id") Long likeUserId) {
        try {
            this.todayBestService.likeUser(likeUserId);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
       * @Description: 不喜欢
       * @Param:[likeUserId]
       * @return:org.springframework.http.ResponseEntity<java.lang.Void>
       * @Author:JinboYang
       * @Date:2021/1/14
       */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> disLikeUser(@PathVariable("id") Long likeUserId) {
        try {
            this.todayBestService.disLikeUser(likeUserId);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
